package com.huatai.datacenter.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huatai.dataservice.entity.SubjectDataSetEntity;
import org.apache.ibatis.annotations.Select;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author gusiyi
 * @version 1.0
 * @className SubjectDataSetMapper
 * @description 描述：
 * @date 2023/6/7 11:57
 */
public interface SubjectDataSetMapper extends BaseMapper<SubjectDataSetEntity> {

	/**
	 * 查看表是否存在
	 * @return
	 */
	@Select("select count(*) from information_schema.TABLES where TABLE_SCHEMA=(select database()) and TABLE_NAME = #{tableName}")
	boolean tableIsExist(String tableName);


	/**
	 * 获取该表的所有字段名与注释
	 * @param tableName
	 * @return
	 */
	@Select("select column_name,column_comment from information_schema.COLUMNS WHERE TABLE_SCHEMA=(select database()) AND TABLE_NAME = #{tableName} ORDER BY ordinal_position;")
	List<LinkedHashMap<String,Object>> getColumns(String tableName);

	/**
	 * 查询该表的总条数
	 * @param tableName
	 * @return
	 */
	@Select("SELECT count(*) from ${tableName}")
	Long countByTableName(String tableName);

	/**
	 * 执行sql语句
	 * @param sql
	 * @return
	 */
	@Select("${sql}")
	List<LinkedHashMap<String,Object>> executeSql(String sql);
}
